package paa.simulator.grafo.simple;


public class PessoaEdge<V extends Object> implements Edge {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private V v1;
	private V v2;
	private double w;

	protected PessoaEdge(V v1, V v2) {
		this.v1 = v1;
		this.v2 = v2;
		this.w = 0;
	}
	
	public V getRelation(V p) {
		if (p.equals(v1)) {
			return v2;
		}
		
		if (p.equals(v2)) {
			return v1;
		}
		
		throw new RuntimeException("Vertex is not a part of this relation");
	}
	
	public void setWeight(double w) {
		this.w = w;
	}
	
	public double getWeight() {
		return w;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((v1 == null) ? 0 : v1.hashCode());
		result = prime * result + ((v2 == null) ? 0 : v2.hashCode());
		return result;
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final PessoaEdge other = (PessoaEdge) obj;
		if (v1 == null) {
			if (other.v1 != null)
				return false;
		} else if (!v1.equals(other.v1))
			return false;
		if (v2 == null) {
			if (other.v2 != null)
				return false;
		} else if (!v2.equals(other.v2))
			return false;
		return true;
	}
}
